package com.example.musicserver.mapper;

import com.example.musicserver.model.MusicInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LoveMusicMapper {
    @Select("select * from music where id in (select music_id from lovemusic where user_id=#{userId})")
    List<MusicInfo> getAllLoveMusic(@Param("userId") Integer userId);

    @Select("select m.* from lovemusic as lm,music as m where lm.music_id=m.id and m.userid=#{userId} " +
            "and m.title like concat('%',#{title},'%')")
    List<MusicInfo> getMusicByTitle(@Param("userId") Integer userId,@Param("title") String title);

    @Select("select user_id from lovemusic where user_id=#{userId} and music_id=#{musicId}")
    Integer getByUidAndMid(@Param("userId") Integer userId,@Param("musicId") Integer musicId);

    @Insert("insert into lovemusic(user_id,music_id) values(#{userId},#{musicId})")
    Integer addLoveMusic(@Param("userId") Integer userId,@Param("musicId") Integer musicId);

//    @Delete("delete from lovemusic where user_id=#{userId} and music_id=#{musicId}")
    Integer deleteLoveMusic(@Param("userId") Integer userId,@Param("musicId") Integer musicId);
}
